package com.mit.service.purchase.dao.impl;

import java.util.HashMap;
import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.purchase.dto.InquiryItemDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.purchase.dao.IInquiryItemDAO;

public class InquiryItemDAOImpl extends AbstractDAO implements IInquiryItemDAO {

	@Override
	public InquiryItemDTO createInquiryItem(InquiryItemDTO to) {
		Integer id = (Integer) getSqlMapClientTemplate().insert("insertInquiryItem", to);
		to.setId(id);
		return to;
	}

	@Override
	public void deleteInquiryItemBelongTo(Integer styleId, Integer colorId) {
		HashMap map = new HashMap();
		map.put("styleId", styleId);
		map.put("colorId", colorId);
		getSqlMapClientTemplate().delete("deleteItemBelongToOneColor", map);
	}

	@Override
	public void deleteInquiryItemBelongTo(Integer fabricId) {
		getSqlMapClientTemplate().delete("deleteItemBelongToOneFabric", fabricId);
		
	}

	@Override
	public List<InquiryItemDTO> retrieveInquiryItems(Integer taskId) {
		
		return (List<InquiryItemDTO>) getSqlMapClientTemplate().queryForList("selectInquiryItemByMstrId", taskId);
	}

	@Override
	public InquiryItemDTO updateInquiryItem(InquiryItemDTO to)
			throws NoRecordUpdateException {
		int row = getSqlMapClientTemplate().update("updateInquiryItem", to);
		if(row == 0 )
			throw new NoRecordUpdateException();
		return to;
	}

}
